home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13097 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Forward declarations: why won't they work?
  5. Date: 23 Mar 1996 13:59:27 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4j103v$ltg@news1.h1.usa.pipeline.com>
  8. References: <4ivpp0$iut@hustle.rahul.net>
  9. NNTP-Posting-Host: 38.8.60.7
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 23, 1996 03:05:04 in article <Forward declarations: why won't they
  16. work?>, 'Theodore Sternberg <strnbrg@rahul.net>' wrote: 
  17.  
  18.  
  19. >Forward class declarations only seem to work sometimes.  When they don't  
  20. >work, I get a compiler error to the effect that "struct foo is an  
  21. >imcomplete type".  Can anyone tell me what's going on, i.e. when forward  
  22. >class declarations are and are not possible? 
  23. Forward declarations do work -- always (unless you have a broken 
  24. compiler, which is very unlikely).  Judging from your wording, 
  25. you are attempting to use a forward-declared class in a manner 
  26. that requires that it be fully defined at the time of usage.  No 
  27. can do. 
  28.  
  29. Example: 
  30.  
  31. class Foo; // fwd decl 
  32.  
  33. class Bar 
  34.  { 
  35.     Foo * pfoo; // OK - it's only a pointer.  Compiler can deal with it. 
  36.     Foo foo;    // illegal.  Compiler doesn't know Foo (yet) 
  37.  
  38.  
  39. -- 
  40. Pete Grant 
  41. Kalevi, Inc. 
  42. Software Engineering & development
  43.